﻿<Window x:Class="BrowserWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:my="clr-namespace:Tools.Metanol"
    xmlns:tCnv="clr-namespace:Tools.WindowsT.WPF.ConvertersT;assembly=Tools.Windows"
    xmlns:ti="clr-namespace:Tools.WindowsT.WPF.InputT;assembly=Tools.Windows"
    Title="{x:Static Tools.Metanol.My.Resources:Resources.txt_DefaultWindowTitle}" Height="529" Width="775" Background="Black" Foreground="Yellow"
    Icon="file:///D:/Users/Honza/Documents/Programy/Tools/Projects/Metanol2/Resources/Metanol.ico" xmlns:Tools.Metanol.My.Resources="clr-namespace:Tools.Metanol.My.Resources"
>
    <Window.Resources>
        <Style TargetType="{x:Type Label}" x:Key="LabelStyle">
            <Setter Property="Foreground" Value="Yellow"/>
            <Setter Property="FontWeight" Value="Normal" />
        </Style>
        <tCnv:BooleanVisibilityConverter x:Key="BooleanVisibilityConverter"/>
        <ti:MouseWheelGesture x:Key="MouseWheelMinus">Minus</ti:MouseWheelGesture>
        <ti:MouseWheelGesture x:Key="MouseWheelPlus">Plus</ti:MouseWheelGesture>
    </Window.Resources>
    <Window.Style>
        <Style TargetType="Window">
            <Style.Triggers>
                <!--Note: These DataTriggers are not reliable, so there is ensuring code in OnIsFullscreenChanged-->
                <DataTrigger Binding="{Binding RelativeSource={RelativeSource Mode=Self}, Path=IsFullscreen}" Value="True">
                    <Setter Property="WindowStyle" Value="None"/>
                    <Setter Property="WindowState" Value="Maximized"/>
                    <Setter Property="ResizeMode" Value="NoResize"/>
                </DataTrigger>
                <DataTrigger Binding="{Binding RelativeSource={RelativeSource Mode=Self}, Path=IsFullscreen}" Value="False">
                    <Setter Property="WindowStyle" Value="SingleBorderWindow"/>
                    <Setter Property="ResizeMode" Value="CanResize"/>
                </DataTrigger>
            </Style.Triggers>
        </Style>
    </Window.Style>
    <Window.CommandBindings>
        <CommandBinding Command="NextPage" Executed="NextPage_Executed"/>
        <CommandBinding Command="PreviousPage" Executed="PreviousPage_Executed"  />
        <CommandBinding Command="my:FileCommands.FileCopy" Executed="FileCopy_Executed"/>
        <CommandBinding Command="my:FileCommands.FileLink" Executed="FileLink_Executed"/>
        <CommandBinding Command="my:DisplayCommands.ToggleFullscreen" Executed="ToggleFullscreen_Executed"/>
        <CommandBinding Command="Close" Executed="Close_Executed" />
        <CommandBinding Command="my:MetanolBrowserCommands.EditIptc" Executed="EditIptc_Executed"/>
        <CommandBinding Command="my:MetanolBrowserCommands.EditRating" Executed="EditRating_Executed"/>
        <CommandBinding Command="Open" Executed="Open_Executed"/>
    </Window.CommandBindings>
    <Window.InputBindings>
        <KeyBinding Gesture="Right" Command="NextPage"/>
        <KeyBinding Gesture="Space" Command="NextPage"/>
        <KeyBinding Gesture="Left" Command="PreviousPage"/>
        <KeyBinding Gesture="Alt+Right" Command="NextPage"/>
        <KeyBinding Gesture="Alt+Left" Command="PreviousPage"/>
        <KeyBinding Gesture="Return" Command="my:DisplayCommands.ToggleFullscreen"/>
        <KeyBinding Gesture="Esc" Command="Close"/>
        <MouseBinding Command="NextPage" Gesture="{StaticResource MouseWheelMinus}"/>
        <MouseBinding Command="PreviousPage" Gesture="{StaticResource MouseWheelPlus}"/>
        <ti:FreeInputBinding Command="Open">
            <ti:FreeInputBinding.Gesture>
                <ti:FreeKeyGesture>O</ti:FreeKeyGesture>
            </ti:FreeInputBinding.Gesture>
        </ti:FreeInputBinding>
    </Window.InputBindings>

    <Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*"/>
            <ColumnDefinition Width="*"/>
            <ColumnDefinition Width="*"/>
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="auto"/>
            <RowDefinition Height="auto"/>
            <RowDefinition Height="auto"/>
            <RowDefinition Height="*"/>
            <RowDefinition Height="auto"/>
        </Grid.RowDefinitions>

        <Menu Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="3" HorizontalAlignment="Stretch" Name="mnuMenu">
            <Menu.Style>
                <Style TargetType="Menu">
                    <Style.Triggers>
                        <DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType=my:BrowserWindow, Mode=FindAncestor}, Path=IsFullscreen}" Value="True">
                            <Setter Property="Visibility" Value="Collapsed"/>
                        </DataTrigger>
                    </Style.Triggers>
                </Style>
            </Menu.Style>
            <MenuItem Header="{x:Static Tools.Metanol.My.Resources:Resources.mni_File}">
                <MenuItem Command="Open" InputGestureText="O, Ctrl+O">
                    <MenuItem.Icon>
                        <Image Source="/MetanolBrowser;component/Images/OpenFile.png" />
                    </MenuItem.Icon>
                </MenuItem>
                <MenuItem Command="my:FileCommands.FileCopy"/>
                <MenuItem Command="my:FileCommands.FileLink"/>
                <MenuItem Command="Close" InputGestureText="Esc"/>
            </MenuItem>
            <MenuItem Header="{x:Static Tools.Metanol.My.Resources:Resources.mni_Image}">
                <MenuItem Command="my:MetanolBrowserCommands.EditIptc" InputGestureText="I"/>
                <MenuItem Command="my:MetanolBrowserCommands.EditRating" InputGestureText="*, Ctrl+R"/>
            </MenuItem>
            <MenuItem Header="{x:Static Tools.Metanol.My.Resources:Resources.mni_Display}">
                <MenuItem Command="my:DisplayCommands.ToggleFullscreen" IsChecked="{Binding RelativeSource={RelativeSource AncestorType=my:BrowserWindow, Mode=FindAncestor}, Path=IsFullscreen, Mode=OneWay}" InputGestureText="Enter, Alt+Enter">
                    <MenuItem.Icon>
                        <Image Source="/MetanolBrowser;component/Images/FullScreenHS.png" />
                    </MenuItem.Icon>
                </MenuItem>
                <MenuItem Command="PreviousPage" InputGestureText="←" Header="{x:Static Tools.Metanol.My.Resources:Resources.mni_PreviousImage}">
                    <MenuItem.Icon>
                        <Image Source="/MetanolBrowser;component/Images/forward.png" />
                    </MenuItem.Icon>
                </MenuItem>
                <MenuItem Command="NextPage" InputGestureText="→, Space" Header="{x:Static Tools.Metanol.My.Resources:Resources.mni_NextImage}">
                    <MenuItem.Icon>
                        <Image Source="/MetanolBrowser;component/Images/Back.png" />
                    </MenuItem.Icon>
                </MenuItem>
            </MenuItem>
        </Menu>
        <ToolBarTray Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="3" HorizontalAlignment="Stretch" IsLocked="True" Name="tbtToolbars">
            <ToolBarTray.Style>
                <Style TargetType="ToolBarTray">
                    <Style.Triggers>
                        <DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType=my:BrowserWindow, Mode=FindAncestor}, Path=IsFullscreen}" Value="True">
                            <Setter Property="Visibility" Value="Collapsed"/>
                        </DataTrigger>
                    </Style.Triggers>
                </Style>
            </ToolBarTray.Style>
            <ToolBar Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="3" HorizontalAlignment="Left">
                <Button Command="PreviousPage">
                    <Button.ToolTip>
                        <TextBlock>
                            <TextBlock Text="{x:Static Tools.Metanol.My.Resources:Resources.tot_PreviousImage}"/>
                            (<TextBlock Text="{x:Static Tools.Metanol.My.Resources:Resources.ltrrtl_PreviousArrow}"/>)
                        </TextBlock>
                    </Button.ToolTip>
                    <Image Source="/MetanolBrowser;component/Images/Back.png" />
                </Button>
                <Button Command="NextPage">
                    <Button.ToolTip>
                        <TextBlock>
                            <TextBlock Text="{x:Static Tools.Metanol.My.Resources:Resources.tot_NextImage}"/>
                            (<TextBlock Text="{x:Static Tools.Metanol.My.Resources:Resources.ltrrtl_NextArrow}"/>)
                        </TextBlock>
                    </Button.ToolTip>
                    <Image Source="/MetanolBrowser;component/Images/forward.png" />
                </Button>
            </ToolBar>
        </ToolBarTray>

        <Image Name="imgImage" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Grid.ColumnSpan="3" Grid.RowSpan="3" Stretch="Uniform" Grid.Row="2">
            <Image.InputBindings>
                <MouseBinding  Command="NextPage" Gesture="RightClick"/>
                <MouseBinding  Command="PreviousPage" Gesture="LeftClick"/>
            </Image.InputBindings>
        </Image>

        <!--IPTC-->
        <Grid Grid.Column="0" Grid.Row="2" HorizontalAlignment="Left" VerticalAlignment="Top" Name="grdIptc" DataContext="{Binding Iptc}">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition Height="auto"/>
                <RowDefinition Height="auto"/>
            </Grid.RowDefinitions>
            <TextBlock Text="{Binding ObjectName}" Grid.Row="0" HorizontalAlignment="Left" TextAlignment="Left"/>
            <TextBlock Grid.Row="1" HorizontalAlignment="Left" TextAlignment="Left">
                <TextBlock Text="{Binding CountryPrimaryLocationCode}"/>,
                <TextBlock Text="{Binding ProvinceState}"/>,
                <TextBlock Text="{Binding City}"/>,
                <TextBlock Text="{Binding SubLocation}"/>
            </TextBlock>
        </Grid>
        <!--System-->
        <Grid Grid.Column="1" Grid.Row="2" HorizontalAlignment="Center" VerticalAlignment="Top" Name="grdSystem" DataContext="{Binding System}">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition Height="auto"/>
                <RowDefinition Height="auto"/>
            </Grid.RowDefinitions>
            <TextBlock Grid.Row="0">
                <TextBlock Text="{Binding FileName}" HorizontalAlignment="Center" TextAlignment="Center"/>
                (
                <TextBlock Text="{Binding RelativeSource={RelativeSource AncestorType=my:BrowserWindow, Mode=FindAncestor}, Path=DisplayIndex}"/>
                /
                <TextBlock Text="{Binding RelativeSource={RelativeSource AncestorType=my:BrowserWindow, Mode=FindAncestor}, Path=Directory.Length}"/>
                )
            </TextBlock>
            <TextBlock Text="{Binding Size, StringFormat='#,###'}" Grid.Row="1" HorizontalAlignment="Center" TextAlignment="Center"/>
        </Grid>
        <!--Exif-->
        <Grid Grid.Column="2" Grid.Row="2" HorizontalAlignment="Right" VerticalAlignment="Top" Name="grdExif" DataContext="{Binding Exif}">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition Height="auto"/>
                <RowDefinition Height="auto"/>
            </Grid.RowDefinitions>
            <TextBlock Text="{Binding IFD0.Exif.DateTimeDigitized}" Grid.Row="0" HorizontalAlignment="Right" TextAlignment="Right"/>
            <TextBlock Grid.Row="1" HorizontalAlignment="Right" TextAlignment="Right">
                <TextBlock Text="{Binding IFD0.Make}"/>
                <TextBlock Text="{Binding IFD0.Model}"/>
            </TextBlock>
        </Grid>

        <!--Ratings-->
        <Label Grid.Column="0" Grid.ColumnSpan="3" Grid.Row="4" HorizontalAlignment="Center" VerticalAlignment="Bottom" DataContext="{Binding Iptc}" Name="lblRating">
            <Label.Resources>
                <Style TargetType="TextBlock" x:Key="l1">
                    <Style.Triggers>
                        <DataTrigger Binding="{Binding .}" Value="0">
                            <Setter Property="Visibility" Value="Collapsed"/>
                        </DataTrigger>
                    </Style.Triggers>
                    <Setter Property="Foreground" Value="Yellow"/>
                </Style>
                <Style TargetType="TextBlock" x:Key="l2">
                    <Style.Triggers>
                        <DataTrigger Binding="{Binding .}" Value="-1">
                            <Setter Property="Text" Value="✖"/>
                            <Setter Property="Foreground" Value="Red"/>
                        </DataTrigger>
                        <DataTrigger Binding="{Binding .}" Value="1">
                            <Setter Property="Text" Value="★"/>
                        </DataTrigger>
                        <DataTrigger Binding="{Binding .}" Value="2">
                            <Setter Property="Text" Value="★★"/>
                        </DataTrigger>
                        <DataTrigger Binding="{Binding .}" Value="3">
                            <Setter Property="Text" Value="★★★"/>
                        </DataTrigger>
                        <DataTrigger Binding="{Binding .}" Value="4">
                            <Setter Property="Text" Value="★★★★"/>
                        </DataTrigger>
                        <DataTrigger Binding="{Binding .}" Value="5">
                            <Setter Property="Text" Value="★★★★★"/>
                        </DataTrigger>
                    </Style.Triggers>
                    <Setter Property="Foreground" Value="Yellow"/>
                </Style>
            </Label.Resources>
            <TextBlock>
                <TextBlock DataContext="{Binding TechnicalQuality}" Style="{StaticResource l1}"><TextBlock Text="{x:Static Tools.Metanol.My.Resources:Resources.txt_TechnicalAbbr}"/> <TextBlock Style="{StaticResource l2}"/></TextBlock>
                <TextBlock DataContext="{Binding ArtQuality}" Style="{StaticResource l1}"><TextBlock Text="{x:Static Tools.Metanol.My.Resources:Resources.txt_ArtAbbr}"/> <TextBlock Style="{StaticResource l2}"/></TextBlock>
                <TextBlock DataContext="{Binding InformationValue}" Style="{StaticResource l1}"><TextBlock Text="{x:Static Tools.Metanol.My.Resources:Resources.txt_InfoAbbr}"/> <TextBlock Style="{StaticResource l2}"/></TextBlock>
                <TextBlock DataContext="{Binding OverallRating}" Style="{StaticResource l1}" FontWeight="Bold"><TextBlock Text="{x:Static Tools.Metanol.My.Resources:Resources.txt_OverallAbbr}"/> <TextBlock Style="{StaticResource l2}"/></TextBlock>
            </TextBlock>
        </Label> 
    </Grid>
</Window>